package com.allwees.bs.core.modelbase.validate;

import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * 参数校验异常，包含所有的错误信息
 *
 * @author yangylsky
 */
public class ValidateException extends IllegalArgumentException {
	private List<String> errorMsgs;

	public ValidateException() {
		super();
	}

	public ValidateException(String msg) {
		super("参数校验错误:" + msg);
		this.errorMsgs = Collections.singletonList(msg);
	}

	public ValidateException(List<String> errorMsgs) {
		super("参数校验错误:\r\n" + getErrMsg(errorMsgs));
		this.errorMsgs = errorMsgs;
	}

	public ValidateException(List<String> errorMsgs, Throwable cause) {
		super("参数校验错误:\r\n" + getErrMsg(errorMsgs), cause);
		this.errorMsgs = errorMsgs;
	}

	public ValidateException(Throwable cause) {
		super(cause);
	}

	public List<String> getErrorMsgs() {
		return errorMsgs;
	}

	public String getErrMsg() {
		return "参数校验错误:\r\n" + getErrMsg(getErrorMsgs());
	}

	private static String getErrMsg(List<String> errorMsgs) {
		return StringUtils.join(errorMsgs, ",\r\n");
	}
}
